package com.jwaoo.mobile.test.repository;

import android.app.Activity;

import com.dx.as.common.ILoadListener;
import com.jwaoo.mobile.test.bean.Story;
import com.jwaoo.mobile.test.model.StorysModel;

import java.util.List;

/**
 * Created by jwaoo on 2017/6/9.
 */

public class StorysPresenter {
    IStorysView storysView;
    private Activity mContext;
    public StorysPresenter(IStorysView storysView, Activity context){
        this.storysView = storysView;
        mContext = context;
    }
    StorysModel model;
    public void getNet(Object ... objects){
        model = StorysModel.getInit(loadListener,mContext.getApplicationContext());
        model.getInfo();
    }

    private ILoadListener<List<Story>> loadListener = new ILoadListener<List<Story>>() {
        @Override
        public void onResponse(final List<Story> response, int flg) {
            mContext.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (response != null && response.size() > 0) {
                        storysView.setStorysList(response);
                    }
                }
            });
        }

        @Override
        public void onFailure(Throwable t) {
            mContext.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    //失败是的特殊处理
                }
            });
        }
    };

}
